home *** CD-ROM | disk | FTP | other *** search
/ Network Support Library / RoseWare - Network Support Library.iso / apidev / sc3x04.exe / VOLRES.C < prev    next >
C/C++ Source or Header  |  1993-06-02  |  7KB  |  207 lines

  1. //   IMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMM;
  2. //   :                                                                    :
  3. //   : module:      volres.c                                              :
  4. //   : abstract:    This module shows how to make 3.x system calls using  :
  5. //   :              the F2 Shell Interface for the Set Directory Disk     :
  6. //   :              Space Restriction API, obviously it requires the      :
  7. //   :              NetWare Shell.                                        :
  8. //   :                                                                    :
  9. //   :              This call may need to be made iteratively to return   :
  10. //   :              all of the restriction information.  For simplicity,  :
  11. //   :              this example only makes the call once.                :
  12. //   :                                                                    :
  13. //   : environment: NetWare 3.x v3.11                                     :
  14. //   :              Borland C 3.1                                         :
  15. //   :                                                                    :
  16. //   :  This software is provided as is and carries no warranty           :
  17. //   :  whatsoever.  Novell disclaims and excludes any and all implied    :
  18. //   :  warranties of merchantability, title and fitness for a particular :
  19. //   :  purpose.  Novell does not warrant that the software will satisfy  :
  20. //   :  your requirements or that the software is without defect or error :
  21. //   :  or that operation of the software will be uninterrupted.  You are :
  22. //   :  using the software at your risk.  The software is not a product   :
  23. //   :  of Novell, Inc. or any of subsidiaries.                           :
  24. //   HMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMM<
  25. //
  26. //     This software is considered pre-release and may be used at your own
  27. //     risk and has been provided due to the many requests of our cust-
  28. //     omers.  Support for this module will be provided at the sole
  29. //     discretion of Novell, Inc.
  30. //
  31.  
  32. #include <stdio.h>
  33. #include <string.h>
  34. #include <stdlib.h>
  35. #include <conio.h>
  36. #include <dos.h>
  37. #include <fcntl.h>
  38. #include <sys\types.h>
  39. #include <sys\stat.h>
  40.  
  41. #include "nwsys.c"
  42.  
  43. //
  44. //  First of all, we define the request structure which is needed for the
  45. //  Set Directory Disk Space Restriction API call.  This structure is
  46. //  laid out according to the System Call documentation.
  47. //
  48.  
  49. struct  REQUEST {
  50.     WORD    sflen;                 // length of the structure
  51.     BYTE    sfcode;                // the subfunction code
  52.     BYTE    volNumber;             // Volume Number
  53.     DWORD   objectID;
  54.     DWORD   diskSpaceLimit;
  55. }Request;
  56.  
  57. // No reply packet required.
  58.  
  59. struct REQUESTID {
  60.     WORD sfLen;        // length of the structure
  61.     BYTE sfCode;       // subfunction code
  62.     BYTE volNumber;    // volume number
  63.     WORD sequence;     // last sequence number
  64.     LONG objectID;     // bindery object ID
  65. } requestID;
  66.  
  67. struct REPLY {
  68.     WORD sequence;     // next sequence number
  69.     LONG objectID;     // bindery object ID
  70.     BYTE accessMask;   // trustee access mask
  71.     BYTE pathLength;   // length of directory path
  72.     BYTE path[255];    // directory path
  73. } reply;
  74.  
  75. struct VOL_REQ {
  76.     WORD sfLen;
  77.     BYTE sfCode;
  78.     BYTE nameLen;
  79.     BYTE name[16];
  80. } volNumReq;
  81.  
  82. struct VOL_REP {
  83.     WORD repLength;
  84.     BYTE volNumber;
  85. } volNumRep;
  86.  
  87. struct BIND_REQUEST {
  88.     WORD  sfLen;            // length of the structure
  89.     BYTE  sfCode;           // subfunction code
  90.     WORD  objectType;       // bindery object type
  91.     BYTE  objectNameLength; // name length: 1 to 47
  92.     BYTE  objectName[48];   // bindery object name
  93. } binderyRequest;
  94.  
  95. struct BIND_REPLY {
  96.     WORD  replyLen;         // length of reply buffer
  97.     DWORD objectID;         // bindery object ID
  98.     WORD  objectType;       // bindery object type
  99.     BYTE  objectName[48];   // bindery object name
  100. } binderyReply;
  101.  
  102. WORD NWSystemCall2(BYTE func,             // function code
  103.                    void far *req,         // request buffer
  104.                    void far *rep)         // reply buffer
  105. {
  106.     union   REGS    regs;
  107.     struct  SREGS   sregs;
  108.  
  109.     segread(&sregs);
  110.  
  111.     memset(®s, 0, sizeof(regs));
  112.  
  113.     regs.h.ah = func;               // AH = function code
  114.     regs.x.si = FP_OFF(req);        // SI = request buffer offset
  115.     regs.x.di = FP_OFF(rep);        // DI = reply buffer offset
  116.  
  117.     sregs.ds = FP_SEG(req);         // DS = request buffer segment
  118.     sregs.es = FP_SEG(rep);         // ES = reply buffer segment
  119.  
  120.     intdosx(®s,®s,&sregs);    // do the Int 21
  121.  
  122.     return (WORD)regs.h.al;         // return code is in AL
  123. }
  124.  
  125. BYTE GetVolumeNumber(char *volName)
  126. {
  127.     int retCode;
  128.  
  129.     volNumReq.sfCode = 0x05;
  130.     volNumReq.nameLen = (BYTE) strlen(volName);
  131.     memmove((char *) &(volNumReq.name), volName, volNumReq.nameLen);
  132.     volNumReq.sfLen = volNumReq.nameLen + 2;
  133.  
  134.     retCode = NWSystemCall2(0xe2, &volNumReq, &volNumRep);
  135.     if (retCode) {
  136.         printf("Get Volume Number failed.  Return code = %d.\n", retCode);
  137.         return(255);
  138.     }
  139.     else
  140.         return(volNumRep.volNumber);
  141. }
  142.  
  143. WORD GetBinderyObjectID(char *userName, WORD objectType, DWORD *objectID)
  144. {
  145.     int retCode;
  146.  
  147.     binderyRequest.sfLen = sizeof(binderyRequest);
  148.     binderyRequest.sfCode = 0x35;
  149.     binderyRequest.objectType = WordSwap(objectType);
  150.     binderyRequest.objectNameLength = strlen(userName);
  151.     strcpy((char *) &(binderyRequest.objectName), userName);
  152.     binderyReply.replyLen = sizeof(binderyReply);
  153.  
  154.     retCode = NWSystemCall2(0xe3, &binderyRequest, &binderyReply);
  155.     *objectID = binderyReply.objectID;
  156.     return(retCode);
  157. }
  158.  
  159.  
  160. int main()
  161. {
  162.     int i, retCode, diskNumber;
  163.     WORD serverConnectionID, objectType;
  164.     DWORD objectID;
  165.     BYTE volNumber;
  166.     char name[80], buffer[20];
  167.  
  168.     printf("Volume name: ");
  169.     gets(name);
  170.  
  171.     volNumber = GetVolumeNumber(name);
  172.  
  173.     if (volNumber == 255)
  174.         return(1);
  175.  
  176.     printf("User name: ");
  177.     gets(name);
  178.     objectType = 1; /* OT_USER */
  179.  
  180.     retCode = GetBinderyObjectID(name, objectType, &objectID);
  181.     if (retCode != 0) {
  182.         printf("Get Bindery Object ID failed.  Return code = %d.\n", retCode);
  183.         return(1);
  184.     }
  185.  
  186.  
  187.     Request.sflen = (sizeof Request) ;
  188.     Request.sfcode = 0x21;                  // subfunction code
  189.     Request.volNumber = volNumber;
  190.     Request.objectID  = objectID;
  191.  
  192.     printf("Enter Disk Space Limit: ");
  193.     Request.diskSpaceLimit = atol (gets(buffer));
  194.  
  195.     retCode = NWSystemCall(0x16, &Request, sizeof(Request),0,0);
  196.     if (retCode == 0)
  197.         printf("Disk Space Restriction Successful\n");
  198.     else {
  199.         printf("Disk Space Restriction failed.  Return code = %d.\n",
  200.             retCode);
  201.         return(1);
  202.     }
  203.  
  204.  
  205.     return(0);
  206. }
  207.